<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:panelGroup >

            <p:growl />

            <p:panel header="Manage Investigation Fees" >

                <p:panelGrid columns="1" >
                    <h:form >
                        <p:panelGrid columns="2" >
                            <h:outputLabel value="Select Investigation" />
                            <p:autoComplete widgetVar="aIx" id="acIx"
                                            forceSelection="true" converter="ixcon" 
                                            value="#{itemFeeController.currentIx}" 
                                            completeMethod="#{investigationController.completeDepartmentItem}" 
                                            var="ix" itemLabel="#{ix.name}" 
                                            itemValue="#{ix}" size="30"  style="width: 400px;">
                                <p:column>#{ix.name}</p:column>
                                <p:column>#{ix.department.name}</p:column>
                                <p:ajax event="itemSelect" process="@this" update=":#{p:component('gpDetail')} :#{p:component('dtbFee')}" listener="#{itemFeeController.createCharges()}"></p:ajax>
                            </p:autoComplete>

                            <p:outputLabel value="Total For Locals"/>
                            <p:outputLabel style="float:right;" id="lblTotal"  value="#{itemFeeController.currentIx.total}">
                                <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                            </p:outputLabel>

                            <p:outputLabel value="Total for Foreigners"/>
                            <p:outputLabel style="float:right;" id="lblFtotal"  value="#{itemFeeController.currentIx.totalFfee}">
                                <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                            </p:outputLabel>


                        </p:panelGrid>
                    </h:form>
                    <p:panelGrid id ="gpVeda" columns="2" styleClass="alignTop" >

                        <p:panel header="Fee List" >
                            <h:form >
                                <p:dataTable id="dtbFee" rowIndexVar="rowIndex" value="#{itemFeeController.charges}" var="bi" >
                                    <p:column headerText="Fee Name">
                                        <h:inputText value="#{bi.name}" style="width: 90px"/>                                        
                                    </p:column>
                                    <p:column headerText="Fee Type">
                                        <h:selectOneListbox size="1" value="#{bi.feeType}" style="width: 120px">
                                            <f:selectItem itemLabel="Select Fee Type"/>
                                            <f:selectItems value="#{enumController.feeTypes}" var="i" itemLabel="#{i.label}" itemValue="#{i}" />                                        
                                        </h:selectOneListbox>
                                    </p:column>
                                    <p:column headerText="Staff/Speciality/Institution/Department" >
                                        <p:outputLabel value="#{bi.speciality.name}" ></p:outputLabel>
                                        <p:outputLabel rendered="#{bi.speciality ne null}" value="&lt;br/&gt;" escape="false" ></p:outputLabel>
                                        <p:outputLabel value="#{bi.staff.person.nameWithTitle}"></p:outputLabel>
                                        <p:outputLabel rendered="#{bi.staff ne null}" value="&lt;br/&gt;" escape="false" ></p:outputLabel>
                                        <h:selectOneListbox id="dtInstitution" size="1"
                                                            value="#{bi.institution}" >
                                            <f:selectItems value="#{institutionController.companies}" var="ins" itemLabel="#{ins.name}" itemValue="#{ins}" />
                                            <f:ajax execute="dtInstitution" render="dtDepartment" event="change"/>                                        
                                        </h:selectOneListbox>
                                        <h:outputLabel value="#{bi.institution.name}"/>
                                        <p:outputLabel rendered="#{bi.institution ne null}" value="&lt;br/&gt;" escape="false" ></p:outputLabel>

                                        <h:selectOneListbox id="dtDepartment" size="1" 
                                                            value="#{bi.department}" >
                                            <f:selectItems value="#{departmentController.items}" var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" />
                                        </h:selectOneListbox>

                                        <h:outputLabel value="#{bi.department.name}"/>
                                    </p:column>                                   

                                    <p:column headerText="Local Fee" >
                                        <p:inputText value="#{bi.fee}" style="width: 60px"/>                                        
                                    </p:column>
                                    <p:column headerText="Foreign Fee">
                                        <p:inputText value="#{bi.ffee}" style="width: 60px"/>                                        
                                    </p:column>

                                    <p:column headerText="Coments">
                                        <h:outputLabel  rendered="#{bi.editer ne null}"  value="Last edit at "/>
                                        <h:outputLabel value="#{bi.editedAt}"  rendered="#{bi.editer ne null}"  >
                                            <f:convertDateTime pattern="dd MMMM yyyy hh:mm a" ></f:convertDateTime>
                                        </h:outputLabel>
                                        <h:outputLabel rendered="#{bi.editer ne null}"  value=" by "/>
                                        <h:outputLabel rendered="#{bi.editer ne null}"  value="#{bi.editer.webUserPerson.nameWithTitle}"/>
                                        <h:outputLabel rendered="#{bi.editer ne null}"  value="."/>
                                    </p:column>
                                    <p:column headerText="Actions">
                                        <p:commandButton ajax="false" value="Update" action="#{itemFeeController.edit(bi)}" style="width: 90px" rendered="#{webUserController.hasPrivilege('LabItemFeeUpadate')}"/>
                                        <p:commandButton id="remove" ajax="false" value="Remove" onclick="if (!confirm('Are you sure you want to delete this record?'))
                                                return false;" action="#{itemFeeController.removeFee}" style="width: 90px" rendered="#{webUserController.hasPrivilege('LabItemFeeDelete')}">
                                            <f:setPropertyActionListener value="#{bi}" target="#{itemFeeController.removedItemFee}"/>
                                        </p:commandButton>
                                    </p:column>
                                </p:dataTable>
                            </h:form>
                        </p:panel>



                        <h:form >
                            <p:panel id="gpDetail" >                                    
                                <f:facet name="header" >
                                    <h:outputLabel value="Add New  Fee" ></h:outputLabel>

                                </f:facet>
                                <p:panelGrid columns="2">
                                    <h:outputText value="Fee Name"/>
                                    <h:inputText autocomplete="off" id="txtFeeName" value="#{itemFeeController.currentFee.name}" required="true" requiredMessage="Please Enter Fee Name" />

                                    <h:outputText value="Fee Type"/>
                                    <h:selectOneListbox size="1" value="#{itemFeeController.currentFee.feeType}" required="true" requiredMessage="Please Select Fee Type">
                                        <f:selectItem itemLabel="Please select the type"/>
                                        <f:selectItems value="#{enumController.feeTypes}" var="i" itemLabel="#{i.label}" itemValue="#{i}" />                                        
                                    </h:selectOneListbox>
                                    <h:outputText value="Speciality"/>
                                    <p:autoComplete converter="specilityCon" forceSelection="true" id="cmbSpe" value="#{itemFeeController.currentFee.speciality}" completeMethod="#{specialityController.completeSpeciality}" var="sp" itemLabel="#{sp.name}" itemValue="#{sp}" size="30"  style="width: 400px;">
                                        <f:ajax execute="cmbSpe" render="cmbDoc" event="select"/>
                                    </p:autoComplete>
                                    <h:outputText value="Staff"/>
                                    <p:autoComplete converter="stfcon" forceSelection="true" id="cmbDoc" value="#{itemFeeController.currentFee.staff}" completeMethod="#{itemFeeController.completeStaff}" var="st" itemLabel="#{st.person.nameWithTitle}" itemValue="#{st}" size="30"  style="width: 400px;">
                                        <f:ajax execute="cmbSpe" event="keypress"/>
                                    </p:autoComplete>


                                    <h:outputText value="Institution"/>
                                    <h:selectOneListbox id="cmbInstitution" size="1"
                                                        value="#{itemFeeController.currentFee.institution}" >
                                        <f:selectItem itemLabel="Select Institution"/>
                                        <f:selectItems value="#{institutionController.companies}" var="ins" itemLabel="#{ins.name}" itemValue="#{ins}" />
                                        <f:ajax execute="cmbInstitution" render="cmbDepartment" event="change"/>                                        
                                    </h:selectOneListbox>
                                    <h:outputText value="Department"/>
                                    <h:selectOneListbox id="cmbDepartment" size="1" value="#{itemFeeController.currentFee.department}" >
                                        <f:selectItem itemLabel="Select Department"/>
                                        <f:selectItems value="#{itemFeeController.institutionDepatrments}" var="dep" itemLabel="#{dep.name}" itemValue="#{dep}" />
                                    </h:selectOneListbox>
                                    <h:outputText value="Local Fee"/>
                                    <h:inputText autocomplete="off" id="txtFee" value="#{itemFeeController.currentFee.fee}"/>
                                    <h:outputText value="Foreigner Fee"/>
                                    <h:inputText autocomplete="off" id="txtFFee" value="#{itemFeeController.currentFee.ffee}"/>

                                    <h:outputText value=""/>
                                    <p:commandButton id="btnAddTo" value="Add"  action="#{itemFeeController.saveCharge}" 
                                                     styleClass="buttons" ajax="false">
                                    </p:commandButton>
                                    <p:defaultCommand target="btnAddTo"/>
                                </p:panelGrid>



                            </p:panel>
                        </h:form>


                    </p:panelGrid>

                </p:panelGrid>





            </p:panel>


        </h:panelGroup>

    </ui:define>

</ui:composition>
